home *** CD-ROM | disk | FTP | other *** search
/ Risc World 5 / Risc World 5.iso / SOFTWARE / Issue3 / Games / xrick / !xrick / src / c / scroller < prev    next >
Text File  |  2004-06-24  |  3KB  |  164 lines

  1. /*
  2.  * xrick/src/scroller.c
  3.  *
  4.  * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved.
  5.  *
  6.  * The use and distribution terms for this software are contained in the file
  7.  * named README, which can be found in the root of this distribution. By
  8.  * using this software in any fashion, you are agreeing to be bound by the
  9.  * terms of this license.
  10.  *
  11.  * You must not remove this notice, or any other, from this software.
  12.  */
  13.  
  14. #include <stdlib.h>
  15.  
  16. #include "system.h"
  17. #include "game.h"
  18. #include "scroller.h"
  19. #include "debug.h"
  20.  
  21. #include "draw.h"
  22. #include "maps.h"
  23. #include "ents.h"
  24.  
  25. static U8 period;
  26.  
  27. /*
  28.  * Scroll up
  29.  *
  30.  */
  31. U8
  32. scroll_up(void)
  33. {
  34.   U8 i, j;
  35.   static U8 n = 0;
  36.  
  37.   /* last call: restore */
  38.   if (n == 8) {
  39.     n = 0;
  40.     game_period = period;
  41.     return SCROLL_DONE;
  42.   }
  43.  
  44.   /* first call: prepare */
  45.   if (n == 0) {
  46.     period = game_period;
  47.     game_period = SCROLL_PERIOD;
  48.   }
  49.  
  50.   /* translate map */
  51.   for (i = MAP_ROW_SCRTOP; i < MAP_ROW_HBBOT; i++)
  52.     for (j = 0x00; j < 0x20; j++)
  53.       map_map[i][j] = map_map[i + 1][j];
  54.  
  55.   /* translate entities */
  56.   for (i = 0; ent_ents[i].n != 0xFF; i++) {
  57.     if (ent_ents[i].n) {
  58.       ent_ents[i].ysave -= 8;
  59.       ent_ents[i].trig_y -= 8;
  60.       ent_ents[i].y -= 8;
  61.       if (ent_ents[i].y & 0x8000) {  /* map coord. from 0x0000 to 0x0140 */
  62.     IFDEBUG_SCROLLER(
  63.       sys_printf("xrick/scroller: entity %#04X is gone\n", i);
  64.       );
  65.     ent_ents[i].n = 0;
  66.       }
  67.     }
  68.   }
  69.  
  70.   /* display */
  71.   draw_map();
  72.   ent_draw();
  73.   draw_drawStatus();
  74.   map_frow++;
  75.  
  76.   /* loop */
  77.   if (n++ == 7) {
  78.     /* activate visible entities */
  79.     ent_actvis(map_frow + MAP_ROW_HBTOP, map_frow + MAP_ROW_HBBOT);
  80.  
  81.     /* prepare map */
  82.     map_expand();
  83.  
  84.     /* display */
  85.     draw_map();
  86.     ent_draw();
  87.     draw_drawStatus();
  88.   }
  89.  
  90.   game_rects = &draw_SCREENRECT;
  91.  
  92.   return SCROLL_RUNNING;
  93. }
  94.  
  95. /*
  96.  * Scroll down
  97.  *
  98.  */
  99. U8
  100. scroll_down(void)
  101. {
  102.   U8 i, j;
  103.   static U8 n = 0;
  104.  
  105.   /* last call: restore */
  106.   if (n == 8) {
  107.     n = 0;
  108.     game_period = period;
  109.     return SCROLL_DONE;
  110.   }
  111.  
  112.   /* first call: prepare */
  113.   if (n == 0) {
  114.     period = game_period;
  115.     game_period = SCROLL_PERIOD;
  116.   }
  117.  
  118.   /* translate map */
  119.   for (i = MAP_ROW_SCRBOT; i > MAP_ROW_HTTOP; i--)
  120.     for (j = 0x00; j < 0x20; j++)
  121.       map_map[i][j] = map_map[i - 1][j];
  122.  
  123.   /* translate entities */
  124.   for (i = 0; ent_ents[i].n != 0xFF; i++) {
  125.     if (ent_ents[i].n) {
  126.       ent_ents[i].ysave += 8;
  127.       ent_ents[i].trig_y += 8;
  128.       ent_ents[i].y += 8;
  129.       if (ent_ents[i].y > 0x0140) {  /* map coord. from 0x0000 to 0x0140 */
  130.     IFDEBUG_SCROLLER(
  131.       sys_printf("xrick/scroller: entity %#04X is gone\n", i);
  132.       );
  133.     ent_ents[i].n = 0;
  134.       }
  135.     }
  136.   }
  137.  
  138.   /* display */
  139.   draw_map();
  140.   ent_draw();
  141.   draw_drawStatus();
  142.   map_frow--;
  143.  
  144.   /* loop */
  145.   if (n++ == 7) {
  146.     /* activate visible entities */
  147.     ent_actvis(map_frow + MAP_ROW_HTTOP, map_frow + MAP_ROW_HTBOT);
  148.  
  149.     /* prepare map */
  150.     map_expand();
  151.  
  152.     /* display */
  153.     draw_map();
  154.     ent_draw();
  155.     draw_drawStatus();
  156.   }
  157.  
  158.   game_rects = &draw_SCREENRECT;
  159.  
  160.   return SCROLL_RUNNING;
  161. }
  162.  
  163. /* eof */
  164.